package zcx;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.09.16.54
 */
public class R4 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        var u=User.class;
        //Method
        for (Method m : u.getDeclaredMethods()) {
            System.out.println(m.getName());

        }
        //Constructor Method
        for (Constructor<?> c : u.getConstructors()) {
            System.out.println(c.getName()+c.getParameterCount());
        }
        //实例化
        var o=u.getConstructor().newInstance();
        var o2=u.getConstructor(int.class,String.class, Date.class,double.class).newInstance(100,"李四",new Date(),10.d);
        var mmm=u.getMethod("getName");
        System.out.println(mmm.invoke(o));
        System.out.println(mmm.invoke(o2));
        //属性
        for (Field f : u.getDeclaredFields()) {
            System.out.println(f.getName());//id
            System.out.println(f.getModifiers());//2->private
            System.out.println(f.getType().getName());//int
        }
        User ls=u.getConstructor().newInstance();
        ls.setName("李四");
        System.out.println(ls.getName());
    }
}
